/**
 *package contains a class Stutter 
 */
 package com.surendra.firstproject.stutterreengineerin;
 
import java.io.*;;
/**
 * A general class declaration which has no instance created
 * <P> Note that {@link words} and {@link line} are default values
 * but not passed from the text file
 * @author surendra
 * @version 4
 * @
 */
public class Stutter{
	
	String words;
	int line;
	/**
	 * Default Constructor
	 */
	public Stutter() {
		words="";
		line=0;
	}
	/**
	 * {@link split} method will take a line of words as parameter and 
	 * split it into string objects
	 * @param lineToWords is a line from a file
	 * @param lineNumber is a line number counter passed as parameter from main
	 */
	public static void split(String lineToWords, int lineNumber) {
		/**
		 * @param lineToWords is splitted and put into String Array
		 */
	String[]words = lineToWords.split(" ");
		/**
		 * @param words and lineNumber, an string array and  integer is passed to compare 
		 * method
		 */
		compare( words, lineNumber);
	}
	/**
	 * {@link compare} method will compare two elements of an array
	 * @param word is an Array paramter that will be passed and two
	 * @param lineNumber carries the line in which the word belongs to
	 */
	public static void compare(String [] word, int lineNumber) {
		
		for(int i=0; i<word.length-1; i++) {
			if(word[i].equals(word[i+1])) {
				/**
				 * if two elements are equal then they will be passed to print method
				 */
			print(lineNumber, word[i],word[i+1]);
			}
		}
	}
	/**
	 *
	 * {@link print} method prints out the the repeated words
	 * @param lineNumber is the lineNumber that a string object belongs to
	 * @param word1 is a repeated word in the line
	 * @param word2 is a repeated word in the line
	 * @throws IOException 
	 */
	public static void print(int lineNumber, String word1, String word2)  {
		/**
		 * prints repeated words as output
		 */
		System.out.println("Words Repeated in "+lineNumber+":"+word1+" "+word2);
	}
	/**
	 * {@link main will get input from the file and execute}
	 * @param args
	 * @throws FileNotFoundException is invoked if file is not available
	 */
	public static void main(String [] args) throws FileNotFoundException {
		/**
		 * A file input
		 */
		BufferedReader inFile= new BufferedReader(new FileReader("TestFile1.txt"));
		
		String line;
		int lineNum=1;
		
		try {
			while((line=inFile.readLine())!=null) {
				/**
				 * trim method is used to remove white spaces
				 */
				line.trim();
				/**
				 * pass @param line and lineNum to @{link split} method
				 */
				split(line,lineNum);
				lineNum++;
			}
			inFile.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
	

